package com.gouqi.mall.mapper;

import com.gouqi.mall.domain.Enterprise;
import com.gouqi.mall.domain.ProductBrand;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EnterpriseMapper {

    @Options(useGeneratedKeys = true,keyProperty = "id")//添加完返回对象中有id值不为null，id自增长
    @Insert("INSERT INTO industry_enterprise(company,cellphone,telephone,address,company_desc,legal_person,founder,scale,home_link,business_scope,qualification,workers_number,logo)" +
            "VALUES(#{company},#{cellphone},#{telephone},#{address},#{companyDesc},#{legalPerson},#{founder},#{scale},#{homeLink},#{businessScope},#{qualification},#{workersNumber},#{logo})")
    Integer addOneCompany(Enterprise company);

    @Update("update industry_enterprise " +
            "set company=#{company}, cellphone=#{cellphone},telephone=#{telephone},address=#{address},company_desc=#{companyDesc},legal_person=#{legalPerson},founder=#{founder}," +
            "scale=#{scale},home_link=#{homeLink},business_scope=#{businessScope},qualification=#{qualification},workers_number=#{workersNumber},logo=#{logo}" +
            "where id=${id}")
    Integer updateOneCompany(Enterprise company);

    @Delete("delete from industry_enterprise where id=#{id}")
    Integer deleteOneCompany(Integer id);

    @Select("select * from industry_enterprise where company like '%${name}%'")
    @Results(id="queryOneCompany",value={
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "company", property = "company"),
            @Result(column = "cellphone", property = "cellphone"),
            @Result(column = "telephone", property = "telephone"),
            @Result(column = "address", property = "address"),
            @Result(column = "company_desc", property = "companyDesc"),
            @Result(column = "legal_person", property = "legalPerson"),
            @Result(column = "founder", property = "founder"),
            @Result(column = "scale", property = "scale"),
            @Result(column = "home_link", property = "homeLink"),
            @Result(column = "business_scope", property = "businessScope"),
            @Result(column = "qualification", property = "qualification"),
            @Result(column = "workers_number", property = "workersNumber"),
            @Result(column = "logo", property = "logo"),
    })
    List<Enterprise> queryOneCompany(@Param(value = "name")String name);

    @Select("select * from industry_enterprise order by id limit #{index},#{pageSize}")
    @Results(id="queryAllCompanies",value={
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "company", property = "company"),
            @Result(column = "cellphone", property = "cellphone"),
            @Result(column = "telephone", property = "telephone"),
            @Result(column = "address", property = "address"),
            @Result(column = "company_desc", property = "companyDesc"),
            @Result(column = "legal_person", property = "legalPerson"),
            @Result(column = "founder", property = "founder"),
            @Result(column = "scale", property = "scale"),
            @Result(column = "home_link", property = "homeLink"),
            @Result(column = "business_scope", property = "businessScope"),
            @Result(column = "qualification", property = "qualification"),
            @Result(column = "workers_number", property = "workersNumber"),
            @Result(column = "logo", property = "logo")
    })
    List<Enterprise> queryAllCompanies(@Param(value = "index")Integer index, @Param(value = "pageSize")Integer pageSize);

    @Select("select count(*) from industry_enterprise")
    Integer queryCountCompanies();

    @Select("select * from industry_enterprise where id=#{id}")
    @Results(id="selectEnterpriseById",value={
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "company", property = "company"),
            @Result(column = "cellphone", property = "cellphone"),
            @Result(column = "telephone", property = "telephone"),
            @Result(column = "address", property = "address"),
            @Result(column = "company_desc", property = "companyDesc"),
            @Result(column = "legal_person", property = "legalPerson"),
            @Result(column = "founder", property = "founder"),
            @Result(column = "scale", property = "scale"),
            @Result(column = "home_link", property = "homeLink"),
            @Result(column = "business_scope", property = "businessScope"),
            @Result(column = "qualification", property = "qualification"),
            @Result(column = "workers_number", property = "workersNumber"),
            @Result(column = "logo", property = "logo"),
            //@Result(column = "id",property = "products",many = @Many(select = "com.gouqi.mall.mapper.EnterpriseProductMapper.findProductsByEnterpriseId"))
    })
    Enterprise selectEnterpriseById(@Param(value = "id")Integer id);

    @Select("select * from industry_enterprise where id=#{id}")
    @Results(id="getCompanies",value={
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "company", property = "company"),
            @Result(column = "cellphone", property = "cellphone"),
            @Result(column = "telephone", property = "telephone"),
            @Result(column = "address", property = "address"),
            @Result(column = "company_desc", property = "companyDesc"),
            @Result(column = "legal_person", property = "legalPerson"),
            @Result(column = "founder", property = "founder"),
            @Result(column = "scale", property = "scale"),
            @Result(column = "home_link", property = "homeLink"),
            @Result(column = "business_scope", property = "businessScope"),
            @Result(column = "qualification", property = "qualification"),
            @Result(column = "workers_number", property = "workersNumber"),
            @Result(column = "logo", property = "logo")
    })
    List<Enterprise> getCompanies(@Param(value = "index")Integer index, @Param(value = "pageSize")Integer pageSize);

    @Select("select * from industry_enterprise where id=#{id}")
    @Results(id="getCompanyById",value={
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "company", property = "company"),
            @Result(column = "cellphone", property = "cellphone"),
            @Result(column = "telephone", property = "telephone"),
            @Result(column = "address", property = "address"),
            @Result(column = "company_desc", property = "companyDesc"),
            @Result(column = "legal_person", property = "legalPerson"),
            @Result(column = "founder", property = "founder"),
            @Result(column = "scale", property = "scale"),
            @Result(column = "home_link", property = "homeLink"),
            @Result(column = "business_scope", property = "businessScope"),
            @Result(column = "qualification", property = "qualification"),
            @Result(column = "workers_number", property = "workersNumber"),
            @Result(column = "logo", property = "logo"),
            @Result(column = "id",property = "products",many = @Many(select = "com.gouqi.mall.mapper.EnterpriseProductMapper.findProductsByEnterpriseId"))
    })
    Enterprise getCompanyById(Integer id);
}
